/****************************************
* Purpose:更改字符型到数值型
*	 Date:20230503	
****************************************/

%macro str2num( indata	/*输入数据集*/
				,vars	/*要改成数值型的变量,空格隔开*/
				,dtvars /*要改成日期型的变量,形式:var1|日期格式1\var2|日期格式2*/
			   )/des="更改字符到数值型";
	%local numOfvars numOfdt exestatements;
	%if %length(&vars)>0 %then %do;
		%let numOfvars=%sysfunc(countw(&vars));
		%do i=1 %to &numOfvars;
			%let var=%scan(&vars,&i);
			%let exestatements=&exestatements _&var=input(&var,??best.)%str(;)drop &var%str(;)rename _&var=&var%str(;);
		%end;
	%end;
	%if %length(&dtvars)>0 %then %do;
		%let numOfdt=%sysfunc(countw(&dtvars,\));
		%do j=1 %to &numOfdt;
			%let varfmt=%scan(&dtvars,&j,\);
			%let var=%scan(&varfmt,1,|);
			%let fmt=%scan(&varfmt,2,|);
			%let exestatements=&exestatements _&var=input(&var,??&fmt)%str(;)format _&var &fmt%str(;)drop &var%str(;)rename _&var=&var%str(;);
		%end;
	%end;
	data &indata;
		set &indata;
		&exestatements
	run;
%mend;